package com.example.first;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity{

    private static final String TAG = "aaa";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView out = findViewById(R.id.txtout);
        out.setText("计算身体质量指数");
  //      EditText input = findViewById(R.id.inp);
        System.out.println("Hello from onCreate()....");
        Log.i("aaa","msg from logi");
        Log.i(TAG,"onCreate:msg abc 123");
        Button btn = findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG,"onClick:1122222222");
                TextView out1 = findViewById(R.id.textView2);
                TextView out2 = findViewById(R.id.textView4);
                EditText input1 = findViewById(R.id.inp);
                EditText input2= findViewById(R.id.inp2);
                if(input1.getText()!=null && input2.getText()!=null);
                double sg = Double.parseDouble(input1.getText().toString());
                double tz = Double.parseDouble(input2.getText().toString());
                double bm=tz/(sg*sg);
                String bmi=String.format("%.2f",bm);
                out1.setText("结果为："+bmi);
                if(bm<18.5){
                   out2.setText("建议：体重偏瘦，建议多食用高热量食物");
                }else if(bm<24){
                    out2.setText("建议：体重正常，继续保持");
                }else if(bm<27){
                    out2.setText("建议：体重偏胖，平时少吃高脂肪食物");
                }else if(bm<30){
                    out2.setText("建议：体重肥胖，建议选择跳绳、跑步等方式健身");
                }else{
                    out2.setText("建议：重度肥胖，坚持长期锻炼，少吃高脂肪");
                }
                }
            }
        );
    }

   /* @Override
    public void onClick(View view) {
        Log.i(TAG,"onClick:click111111");
        TextView out = findViewById(R.id.txtout);
        EditText edit = findViewById(R.id.inp);
        String str= edit.getText().toString();
        out.setText("Hello2"+str);
    }*/
}